/**
 * @classDescription  评分构造函数
 * @type {Object}
 * @param {String | Object} 评分栏的ID或者DOM对象
 * @param {String | Object} 显示评分结果的id或者Dom对象 
 */ 
function Grade(id1, id2){
	this.el1 = Kg.$(id1);
	this.el2 = Kg.$(id2);
	this.span = Kg.$T("span", this.el1);
	this.selected = false;
	this.selectedIndex = null;

	Kg.addEvent(this.el1, "mouseover", Kg.bind(function(e){
		e = e || window.event;
		eSrc = e.target || e.srcElement;
		if(eSrc.tagName.toLowerCase() == "span"){
			this.clear();
			this.setGrade(Kg.indexOf(this.span, eSrc));
		}
	}, this));

	Kg.addEvent(this.el1, "mouseout", Kg.bind(function(e){
		e = e || window.event;
		eSrc = e.target || e.srcElement;
		var toEl = e.toElement || e.relatedTarget;

		if(!Kg.isFather(this.el1, toEl, true)){
			this.clear();
			if(this.selected)	this.setGrade(this.selectedIndex);
		}
	}, this));

	Kg.addEvent(this.el1, "click", Kg.bind(function(e){
		e = e || window.event;
		eSrc = e.target || e.srcElement;
		if(eSrc.tagName.toLowerCase() == "span"){
			this.selected = true;		
			this.selectedIndex = Kg.indexOf(this.span, eSrc);
		}
	}, this))
};

Grade.prototype.setGrade = function(index){
	this.el2.innerHTML = this.span[index].innerHTML;
	while(index>=0){
		this.span[index].className += " hover";
		--index;
	}
};

Grade.prototype.clear = function(){
	this.el2.innerHTML = "";
	for(var i = 0, l = this.span.length; i < l; i++){
		this.span[i].className = this.span[i].className.replace(/\s*hover/, "");
	}
}